cmake_minimum_required(VERSION 3.0.2)
project(cotton_detect)
#set(CMAKE_CXX_STANDARD 14)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES mm
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)


# cuda
find_package(CUDA REQUIRED)
message(STATUS "Find CUDA include at ${CUDA_INCLUDE_DIRS}")
message(STATUS "Find CUDA libraries: ${CUDA_LIBRARIES}")

# TensorRT
#set(TENSOR_ROOT /home/xag/TensorRT-7.0.0.11/)   # in other device is need this line, except in pure nvidia 
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
        HINTS ${TENSORRT_ROOT} PATH_SUFFIXES include/)
message(STATUS "Found TensorRT headers at ${TENSORRT_INCLUDE_DIR}")
find_library(TENSORRT_LIBRARY_INFER nvinfer
        HINTS ${TENSORRT_ROOT} ${TENSORRT_BUILD} ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES lib lib64 lib/x64)
find_library(TENSORRT_LIBRARY_ONNXPARSER nvonnxparser
        HINTS ${TENSORRT_ROOT} ${TENSORRT_BUILD} ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES lib lib64 lib/x64)
set(TENSORRT_LIBRARY ${TENSORRT_LIBRARY_INFER} ${TENSORRT_LIBRARY_ONNXPARSER})
message(STATUS "Find TensorRT libs: ${TENSORRT_LIBRARY}")

# OpenCV
find_package(OpenCV REQUIRED)
message(STATUS "Find OpenCV include at ${OpenCV_INCLUDE_DIRS}")
message(STATUS "Find OpenCV libraries: ${OpenCV_LIBRARIES}")

#set(COMMON_INCLUDE src/includes/common)

# realsense2
set( CMAKE_BUILD_TYPE Debug )
set(DEPENDENCIES realsense2 )

## 链接和调用动态库(.so)
# 指定头文件目录路径
set(INC_COTTON /home/nvidia/code/catkin_ws/src/cotton_detect/src/include)
# 或者直接使用头文件目录的绝对路径 include_directories("/home/xag/code/trt_code/dynamic_link_test/include")
# 链接库，需要动态库的绝对路径
link_libraries("/home/nvidia/code/catkin_ws/src/cotton_detect/src/library/libcotton_detect.so")
# 指定头文件目录
include_directories(${CUDA_INCLUDE_DIRS} ${TENSORRT_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS} ${COMMON_INCLUDE} ${INC_COTTON}) #${realsense2_INCLUDE_DIR}

add_executable(cotton_detect src/main.cpp)
target_link_libraries(cotton_detect ${DEPENDENCIES} ${OpenCV_LIBRARIES} ${CUDA_LIBRARIES} ${TENSORRT_LIBRARY} ${catkin_LIBRARIES} )

